<!DOCTYPE html>
<html xmlns:background-color="http://www.w3.org/1999/xhtml">
<head lang="en">
    <meta charset="UTF-8">
    <title>管理员登陆</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>[title]</title>

    <!-- Bootstrap core CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>

    <link href="__STATIC__/css/ui-dialog.css" rel="stylesheet">

    <!-- Add custom CSS here -->
    <link href="__STATIC__/css/sb-admin.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/font-awesome/css/font-awesome.min.css">
</head>
<body style="background-color:#222222">
<div class="container" style="margin-top:200px">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <h1 style="color:white">管理员登陆</h1>

            <form action="{:U('login/login')}" method="post" onSubmit="return checkInput(this)">
                <div class="form-group">
                    <label for="inputUser" style="color:white">用户名</label>
                    <input type="text" name="username" class="form-control" id="inputUser" placeholder="用户名">
                </div>
                <div class="form-group">
                    <label for="inputPassword" style="color:white">密码</label>
                    <input type="password" name="password" class="form-control" id="inputPassword"
                           placeholder="密码">
                </div>
                <div class="form-group">
                    <label for="inputCode" style="color:white">验证码</label>

                    <div class="row">
                        <div class="col-md-8">
                            <input type="text" name="verify" class="form-control" id="inputCode"
                                   placeholder="验证码">
                        </div>
                        <div class="col-md-4" name="verify_code">
                            <a href="javascript:void(0)"><img class="verify" src="{:U('login/verify')}" alt="点击刷新"/></a>
                        </div>
                    </div>
                </div>
                <button type="submit" class="btn btn-success align:right">登陆</button>
            </form>
        </div>
    </div>
</div>
<script src="__STATIC__/js/jquery-1.10.2.js"></script>
<script src="__STATIC__/js/dialog-min.js"></script>
<script>
    $(function () {
        $(".verify").click(function () {
            var src = "{:U('login/verify')}";
            var random = Math.floor(Math.random() * (1000 + 1));
            $(this).attr("src", src + "&random=" + random);

        });
    })

    function checkInput(form) {
        if (form.username.value.replace(/(^\s*)|(\s*$)/g, "") == "") {

            var d = dialog({
                content: '请输入用户名',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('inputUser'));
        }
        else if (form.password.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            var d = dialog({
                content: '请输入密码',
                align: 'right',
                quickClose: true
            });

            d.show(document.getElementById('inputPassword'));
        }
        else if (form.verify.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
            var d = dialog({
                content: '请输入验证码',
                align: 'left',
                quickClose: true
            });

            d.show(document.getElementById('inputCode'));
        }

        if (d != null) {
            setTimeout(function () {
                d.close().remove();
            }, 2000);

            return false;
        }
        return true;
    }

    var currentTime = new Date().getTime();
    function require() {
        $.ajax({
            url: "{:U('Warn/checkWarn')}",
            type: 'POST',
            dataType: 'json',
            timeout: 80000,
            data: {
                time: currentTime
            },
            success: function (data) {
                if (data.status) {
                    showWarn(data.warn_obj,data.warn_type);
                }
                else {
//                    showWarn("login <br>" + data.warn_obj);
                }
            },
            error: function () {
            }
        });

        currentTime = new Date().getTime();
        setTimeout('require()', 3000);
    }


    function showWarn(id,type) {

        var d = dialog({
            title: '警告',
            content: '<html><body><p style="color:red">发现可疑人员信息('+type+'),<br>请及时通知相关部门<p><audio autoplay="true" loop ="1" src="./Admin/View/warn.mp3"/></body></html>',
            okValue: '查看',
            ok: function () {
                window.location.href = "{:U('Index/info?key=')}" + id;
                return false;
            },
            cancelValue: '取消',
            cancel: function () {
            }
        });
        $isShow = true;
        d.show();
//        setTimeout(function () {
//            d.close();
//        }, 3000)
    }
    window.onload = require;
</script>
</body>
</html>